<template>
  <div class="form-group">
    <label :for="id" class="form-label">{{ label }}</label>
    <div class="input-wrapper">
      <i :class="`fa ${icon} input-icon`"></i>
      <input 
        :id="id"
        :value="modelValue"
        @input="$emit('update:modelValue', $event.target.value)"
        :type="type"
        :placeholder="placeholder"
        class="form-control"
        :class="{ 'has-value': modelValue }"
        :required="required"
      >
    </div>
  </div>
</template>

<script setup>
defineProps({
  id: {
    type: String,
    required: true
  },
  label: {
    type: String,
    required: true
  },
  icon: {
    type: String,
    required: true
  },
  modelValue: {
    type: [String, Boolean],
    default: ''
  },
  type: {
    type: String,
    default: 'text'
  },
  placeholder: {
    type: String,
    default: ''
  },
  required: {
    type: Boolean,
    default: false
  }
})

defineEmits(['update:modelValue'])
</script>

<style scoped>
.form-group {
  margin-bottom: 1.5rem;
}

.form-label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: #374151;
  font-size: 0.875rem;
}

.input-wrapper {
  position: relative;
}

.input-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: #9ca3af;
  z-index: 1;
}

.form-control {
  width: 100%;
  padding: 0.875rem 1rem 0.875rem 3rem;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  font-size: 1rem;
  box-sizing: border-box;
  background-color: #fff;
  color: #1f2937;
}

.form-control:focus {
  outline: none;
  border-color: #4f46e5;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-control::placeholder {
  color: #9ca3af;
}

.form-control:hover {
  border-color: #9ca3af;
}

/* 响应式设计 */
@media (max-width: 480px) {
  .form-control {
    padding: 0.75rem 1rem 0.75rem 2.75rem;
    font-size: 1rem;
  }
  
  .input-icon {
    left: 0.875rem;
  }
}
</style>
